package com.charles.springmvc.web.ch4_3;

import com.charles.springmvc.domain.DemoObj;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by leo on 2017/5/4.
 */

@Controller
@RequestMapping
public class DemoAnnoController {

    @RequestMapping(produces = "text/plan;charset=UTF-8")
    public @ResponseBody
    String index(HttpServletRequest request) {
        return "url:" + request.getRequestURL() + " can access";
    }

    @RequestMapping(value = "/pathvar/{str}", produces = "text/plan;charset=UTF-8")
    public @ResponseBody String demoPathVar(@PathVariable String str, HttpServletRequest request) {
        return "url:" + request.getRequestURL() + " can access,str:" + str;
    }

    @RequestMapping(value = "/requestParam", produces = "text/plan;charset=UTF-8")
    public @ResponseBody
    String passRequestParam(Long id, HttpServletRequest request) {
        return "url:" + request.getRequestURL() + " can access,id:" + id;
    }

    @RequestMapping(value = "/obj", produces = "text/plan;charset=UTF-8")
    @ResponseBody
    public String passObj(DemoObj obj, HttpServletRequest request) {
        return "url:" + request.getRequestURL() + " can access,obj id:" + obj.getId();
    }

    @RequestMapping(value = {"/name1","/name2"}, produces = "text/plan;charset=UTF-8")
    public @ResponseBody String remove(@PathVariable String str, HttpServletRequest request) {
        return "url:" + request.getRequestURL() + " can access,str:" + str;
    }

}
